#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<assert.h>
#include<string.h>

#define FILE_NAME "log.txt"



int main()
{
    
    umask(0);

    //int ret = open(FILE_NAME ,O_WRONLY | O_CREAT | O_TRUNC,0666);
    int ret = open(FILE_NAME ,O_RDONLY);

    if(ret<0)
    {
        perror("open");
        return 1;
    }
 

    char buffer[1024];

    ssize_t num = read(ret,buffer,sizeof(buffer)-1);

    if(num>0)
    {
        buffer[num]=0;
    }

    printf("%s\n",buffer);




    //int cnt = 5;

    //char outbuffer[64];

    //while(cnt)
    //{
    //    sprintf(outbuffer,"%s:%d\n","陈自豪大傻呗",cnt--);
    //    write(ret,outbuffer,strlen(outbuffer));
    //}

    //printf("ret: %d\n",ret);
    //write(ret,);

    close(ret);
    
    










    //FILE*fp = fopen(FILE_NAME,"w");
    //FILE*fp = fopen(FILE_NAME,"r");
    //FILE*fp = fopen(FILE_NAME,"a");
    
    //if(NULL==fp)
    //{
    //    perror("fopen");
    //    return 1;
    //}
//
//    int cnt = 5;
//    while(cnt)
//    {
//        fprintf(fp,"%s:%d\n","你好，陈自豪",cnt--);
//
//    }
    
    //char buffer[64];

    //while(fgets(buffer,sizeof(buffer),fp)!=NULL)
    //{
        //puts(buffer);
    //    printf("%s",buffer);
    //}



//    fclose(fp);
    
    
    
    
    
    
    
    return 0;
}
